<%@page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>部门用户分配</title>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="${ctx}/js/tree/zTreeStyle/zTreeStyle.css" />
<style type="text/css">
/*文档*/
body{margin:0;width:100%;}
/*部门用户层*/
#div_deptUser{margin:10px;}
/*部门用户表*/
#tb_deptUser,#tb_unassignedUser,#tb_assignedUser{width:100%;border-collapse:collapse;} 
/*部门用户表列*/
#tb_deptUser td,#tb_unassignedUser td,#tb_assignedUser td{text-align:center;border:1px solid #6EA5EB;}
/*表、列标题行高*/
#tr_tb_title,#tr_col_title{height:30px;}
/*列标题行*/
#tr_col_title{background-color:#DFEFFF;}
/*所有部门、未、已分配用户列*/
#td_allDept,#td_unassignedUser,#td_assignedUser{width:33%;}
/*部门层、已、未分配用户层*/
#div_dept,#div_assignedUser,#div_unassignedUser{width:100%;height:350px;margin:0;overflow:auto;}
/*部门树*/
#ul_tree{margin:0;padding:0;}
/*已、未分配用户标题行*/
#tr_unassignedUser,#tr_assignedUser{background-color:#D4D0C8;}
/*奇、偶、悬停行*/
.odd{background-color:#f7fbff;}.even{background-color:#ffffff;}.over{background-color:#fdfad0;}
</style>
<script type="text/javascript" src="${ctx }/js/jquery/jquery.js"></script>
<script type="text/javascript" src="${ctx }/js/tree/jquery-ztree.js"></script>
<script type="text/javascript" src="${ctx }/js/include/get.js"></script>
<script type="text/javascript">
$(function(){
	//加载
	$("#tb_unassignedUser tr:first td").css("border-top","0");$("#tb_unassignedUser td:first-child").css("border-left","0");$("#tb_unassignedUser td:last-child").css("border-right","0");$("#tb_assignedUser tr:first td").css("border-top","0");$("#tb_assignedUser td:first-child").css("border-left","0");$("#tb_assignedUser td:last-child").css("border-right","0");
	$.post("${ctx}/manage/sys/dept/getDepartment2.htm",function(data){
		_ztree=$("#ul_tree").zTree({isSimpleData:true,treeNodeKey:"id",treeNodeParentKey:"pid",callback:{click:ztreeClick},expandSpeed:""},eval(data));
	});
	//单击树
	function ztreeClick(){
		$("#tb_unassignedUser>tbody>tr:gt(0)").remove();
		$("#tb_assignedUser>tbody>tr:gt(0)").remove();
		$.post("${ctx}/manage/sys/user/getUnassignedUserByDeptid.htm",{deptid:_ztree.getSelectedNode().id},function(data){
			$(eval(data)).each(function(i){
				$("#tb_unassignedUser").append("<tr class='"+(0==i%2?"even":"odd")+"'><td>"+this.name+"</td><td>"+this.account+"</td><td><a id='"+this.id+"' href='#' class='a_add'>添加</a></td></tr>");
			});
			_highLight();$("#tb_unassignedUser tr:first td").css("border-top","0");$("#tb_unassignedUser td:first-child").css("border-left","0");$("#tb_unassignedUser td:last-child").css("border-right","0");
			$(".a_add").click(function(){
				$.post("${ctx}/manage/sys/assignDeptUser2.htm",{userid:this.id,deptid:_ztree.getSelectedNode().id},function(data){
					if(1==data){alert("添加成功！");ztreeClick();
					}else alert("添加失败！");
				});
			});
		});
		$.post("${ctx}/manage/sys/user/getAssignedUserByDeptid.htm",{deptid:_ztree.getSelectedNode().id},function(data){
			$(eval(data)).each(function(i){
				$("#tb_assignedUser").append("<tr class='"+(0==i%2?"even":"odd")+"'><td>"+this.name+"</td><td>"+this.account+"</td><td><a id='"+this.deleteId+"' href='#' class='a_del'>删除</a></td></tr>");
			});
			_highLight();$("#tb_assignedUser tr:first td").css("border-top","0");$("#tb_assignedUser td:first-child").css("border-left","0");$("#tb_assignedUser td:last-child").css("border-right","0");
			$(".a_del").click(function(){
				$.post("${ctx}/manage/sys/delUserDeptById.htm",{id:this.id},function(data){
					if(1==data){alert("删除成功！");ztreeClick();
					}else alert("删除失败！");	
				});
			});
		});
	}
});
</script>
</head>
<body>
<div id="div_deptUser">
<table id="tb_deptUser" cellpadding="0">
	<tr id="tr_tb_title">
		<td colspan="3">部门员工分配</td>
	</tr>
	<tr id="tr_col_title">
		<td id="td_allDept">所有部门</td><td id="td_unassignedUser">待分配员工</td><td id="td_assignedUser">已分配员工</td>
	</tr>
	<tr>
		<td id="td_deptData">
			<div id="div_dept"><ul id="ul_tree" class="tree" /></div>
		</td>
		<td id="td_unassignedUserData">
			<div id="div_unassignedUser">
			<table id="tb_unassignedUser" cellpadding="0">
				<tr id="tr_unassignedUser">
					<td>姓名</td><td>账号</td><td>操作</td>
				</tr>
			</table>
			</div>
		</td>
		<td id="td_assignedUserData">
			<div id="div_assignedUser">
			<table id="tb_assignedUser" cellpadding="0">
				<tr id="tr_assignedUser">
					<td>姓名</td><td>账号</td><td>操作</td>
				</tr>
			</table>
			</div>
		</td>
	</tr>
</table>
</div>
</body>
</html>
